#!/bin/bash

# load config

if [ -f .env ]; then
	export $(cat .env | sed 's/#.*//g' | xargs)
fi

# install softwares

export DEBIAN_FRONTEND=noninteractive
sudo apt -y update
# sudo apt -qy -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgrade

sudo apt install -y \
	vim \
	git \
	htop  \
	lrzsz  # 方便与 windows 之间传递文件 \
	autojump \

# 配置 autojump
# source /usr/share/autojump/autojump.sh on startup
# echo '. /usr/share/autojump/autojump.sh'>>~/.bashrc

# if [ -z $GIT_USER ] && [ -z $GIT_EMAIL ]; then
# 	git config --global user.name yangxiyuan
# 	git config --global user.email 261524245@qq.com
# fi
# git config --global credential.helper store

# ===
# basic config & vim

sudo git clone https://gitee.com/SimonInOSC/my-server.git ~/.server
echo "for alias in ~/.server/aliases/*
	do . \$alias
done" >> ~/.bashrc

sudo source ~/.bashrc

# git clone https://github.com/takashiki/my-vim.git ~/.vim
# git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# echo "source ~/.vim/my.vim" > ~/.vimrc

# ===
# config ssh port and key

# if [ ! -z $SSH_PORT ]; then
# 	echo "Port $SSH_PORT" >> /etc/ssh/sshd_config
# fi

# if [ ! -d ~/.ssh ]; then
# 	mkdir ~/.ssh
# 	chmod 700 ~/.ssh
# fi

# if [ ! -z $PUB_KEY ] && [ -f $PUB_KEY ]; then
# 	cat $PUB_KEY >> ~/.ssh/authorized_keys
# 	chmod 600 ~/.ssh/authorized_keys
# fi

# service ssh restart

# ===
# install docker https://www.cnblogs.com/songxi/p/12788249.html

export $(cat /etc/os-release | grep ID | xargs)

sudo apt remove docker docker-engine docker.io containerd runc

sudo apt install -y \
	apt-transport-https \
	ca-certificates \
	curl \
	gnupg-agent \
	software-properties-common

sudo curl -fsSL https://download.docker.com/linux/$ID/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88

sudo add-apt-repository \
	"deb [arch=amd64] https://download.docker.com/linux/$ID \
	$(lsb_release -cs) \
	stable"

# apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose

# # if [ ! -z $DOCKER_MIRROR ]; then
# # 	curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s $DOCKER_MIRROR
# # 	service docker restart
# # fi

sudo docker run hello-world
